package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.privilege.model.User;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

@Entity
@Indexed
@Table(name = "fp_approvalprocess")
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter="sequenceNumber,checkTime") })
public class ApprovalProcess extends BaseModel {
	
	private static final long serialVersionUID = 5716307740260423492L;

	@Id
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkApprovalProcess;

	/** 序号 */
	@Column
	@Field
	private Integer sequenceNumber;
	
	/** 对应审批流程条目 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="pkApprovalInstance")
	private ApprovalInstance approvalInstance;
	
	/** 审批日期 */
	@Column
	@Field
	@Between
	private  Date checkTime;
	
	/** 审批意见 */
	@Column
	@Field
	private  String  note;
	
	/** 审批人 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkChecker")
	@IndexedEmbedded(depth = 1)
	private  User checker;
	
	/** 提交人 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkCreator")
	@IndexedEmbedded(depth = 1)
	private User creator;
	
	/** 提交日期 */
	@Column
	@Field
	@Between
	private  Date commitTime;
	
	
	/** 审批状态 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private  Status status;
	
	/** 审批状态 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status 
	{
		Commit("提交"),
		Initial("初始"),
		Pass("通过"), 
		NotPass("驳回"), 
		Plus("加签"), 
		Agent("代签");
		

		private String display;

		Status(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}
	
	/**是否代理审批*/
	@Column
	@Field
	private  Boolean agent;
	
	/** 代理审批人 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkAgentChecker")
	@IndexedEmbedded(depth = 1)
	private  User agentChecker;
	
	/** 代理审批人 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkPlusChecker")
	@IndexedEmbedded(depth = 1)
	private  User plusChecker;
	
	@Version
	private Integer version;

	public Long getPkApprovalProcess() {
		return pkApprovalProcess;
	}

	public void setPkApprovalProcess(Long pkApprovalProcess) {
		this.pkApprovalProcess = pkApprovalProcess;
	}

	public ApprovalInstance getApprovalInstance() {
		return approvalInstance;
	}

	public void setApprovalInstance(ApprovalInstance approvalInstance) {
		this.approvalInstance = approvalInstance;
	}

	public Date getCheckTime() {
		return checkTime;
	}

	public void setCheckTime(Date checkTime) {
		this.checkTime = checkTime;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public User getChecker() {
		return checker;
	}

	public void setChecker(User checker) {
		this.checker = checker;
	}

	public User getCreator() {
		return creator;
	}

	public void setCreator(User creator) {
		this.creator = creator;
	}

	public Date getCommitTime() {
		return commitTime;
	}

	public void setCommitTime(Date commitTime) {
		this.commitTime = commitTime;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Boolean getAgent() {
		return agent;
	}

	public void setAgent(Boolean agent) {
		this.agent = agent;
	}

	public User getAgentChecker() {
		return agentChecker;
	}

	public void setAgentChecker(User agentChecker) {
		this.agentChecker = agentChecker;
	}

	public User getPlusChecker() {
		return plusChecker;
	}

	public void setPlusChecker(User plusChecker) {
		this.plusChecker = plusChecker;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Integer getSequenceNumber() {
		return sequenceNumber;
	}

	public void setSequenceNumber(Integer sequenceNumber) {
		this.sequenceNumber = sequenceNumber;
	}

}
